package top.humbleyuan.hash;

import java.util.HashMap;

/**
 * @Author HumbleYuan
 * @Date 2020/5/18 20:44
 * @Des 多数元素
 * @pro 待补充分治法
 */
public class LeetCode_169 {
    public static void main(String[] args) {
        HashMap<Integer, Integer> map = new HashMap<>();

        int[] nums = {3, 2, 3, 3};
        int i;
        for (i = 0; i < nums.length; i++) {
            int num = map.getOrDefault(nums[i], 0);

            map.put(nums[i], num + 1);
            if((num + 1) > nums.length / 2) {
                System.out.println(nums[i]);
                return;
            }
        }

        System.out.println(nums[i - 1]);
    }
}
